<?php

namespace App\Models;


use App\Service\Base\Model;

class SiteInfo extends Model
{

    // 用户管理
    protected $table = 'site_info';

    // 缓存字段，用于搜索绑定的字段
    protected $cacheFields = ['id'];

    //  {"id":"编号","title":"名称","key":"唯一关键词（用于调用）","en_content":"内容（英文）","cn_content":"内容（中文）","tc_content":"内容（繁体）","status":"状态 1-正常 0-禁用","ctime":"创建时间","mtime":"修改时间"}


    //[ 'id', 'title', 'key', 'en_content', 'cn_content', 'tc_content', 'status', 'ctime', 'mtime',]


    //array ( 'id' => '$this->getData("id", null, "trim")', 'title' => '$this->getData("title", null, "trim")', 'key' => '$this->getData("key", null, "trim")', 'en_content' => '$this->getData("en_content", null, "trim")', 'cn_content' => '$this->getData("cn_content", null, "trim")', 'tc_content' => '$this->getData("tc_content", null, "trim")', 'status' => '$this->getData("status", null, "trim")', 'ctime' => '$this->getData("ctime", null, "trim")', 'mtime' => '$this->getData("mtime", null, "trim")', )

    //$id = $this->getData("id", null, 'trim'); $title = $this->getData("title", null, 'trim'); $key = $this->getData("key", null, 'trim'); $en_content = $this->getData("en_content", null, 'trim'); $cn_content = $this->getData("cn_content", null, 'trim'); $tc_content = $this->getData("tc_content", null, 'trim'); $status = $this->getData("status", null, 'trim'); $ctime = $this->getData("ctime", null, 'trim'); $mtime = $this->getData("mtime", null, 'trim');


    // 获取所有的话题信息
    public function getAll($where = [], $order = 'id DESC')
    {
        // 获取缓存
        $bang     = $this->bang;
        $is_cache = $this->is_cache || $bang;
        $args     = compact('where');
        if($is_cache){
            $cacheName = $this->cacheKey('lists', $args);
            $cacheData = $this->cacheClass()->getCache($cacheName);
            if(!empty($cacheData)){
                // 检查是否已经绑定
                $this->checkBangList($cacheData, $cacheName);

                return $cacheData;
            }
        }

        // 查询
        if(is_array($order)){
        } else{
            $order = explode(" ", $order);
        }

        $lists = $this->where($where)->orderby($order[0], $order[1])->get()->toArray();
        $lists = array_column($lists, null, 'id');
        // 保存为缓存
        if($is_cache){
            $this->addCacheList($lists, $cacheName, $lists, 'list');
        }

        return $lists;
    }

    // 获取详情

    // 保存


    // 定义验证操作
    public function rules()
    {

        $add = [
        ];

        $edit = [
        ];

        $info = [
        ];


        $rule = [
            //'id'         => 'required',
            'title'  => 'required',
            //'key'        => 'required',
            //'en_content' => 'required',
            //'cn_content' => 'required',
            //'tc_content' => 'required',
            'status' => ['in:0,1,2'],
            //'ctime'      => 'required',
            //'mtime'      => 'required',
        ];


        $msg = [
            //'status'  => '状态 1-正常 0-禁用',
            'id'         => '编号',
            'title'      => '名称',
            'key'        => '唯一关键词（用于调用）',
            'en_content' => '内容（英文）',
            'cn_content' => '内容（中文）',
            'tc_content' => '内容（繁体）',
            'status'     => '状态 1-正常 0-禁用',
            'ctime'      => '创建时间',
            'mtime'      => '修改时间',
        ];

        return ['rule' => $rule, 'msg' => $msg, 'add' => $add];
    }
}
